package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/30 10:18
 * @apiNote
 */

public class Test00868BinaryGap {
    public int binaryGap(int n) {
        int last = -1,ans = 0;
        for(int i =0;n!=0;i++){
            if((n&1)==1){
                if(last != -1){
                    ans = Math.max(ans,i-last);
                }
                last = i;
            }
            n >>=1;
        }
        return ans;
    }
}
